package com.example.cinema.adapter;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.example.cinema.R;

import java.util.ArrayList;
import java.util.List;
//内容图片展示适配器
public class ImagePageAdapter extends PagerAdapter {

    private Context context;
    private LayoutInflater inflater;
    private List<String> data;
    private int Brid;
    private List<View> views = new ArrayList<>();
    public ImagePageAdapter(Context context, List<String> data, int brid) {
        this.context = context;
        this.data = data;
        Brid = brid;
        this.inflater = LayoutInflater.from(context);
        for (int i=0;i<data.size();i++)
        {
            ImageView imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            Glide.with(imageView).load(data.get(i)).into(imageView);
            views.add(imageView);
        }
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {

        container.addView(views.get(position));
        return views.get(position);
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(views.get(position));
    }
}
